Repository navigation
Expose response body and GraphQL errors on GraphQLHttpException - #16
Merged
Merged
Conversation
On a non-success HTTP status, read the response body (best effort) and expose it on GraphQLHttpException: - ResponseBody: the raw body, always available when non-empty - Response: a GraphQLResponse parsed from the body when it is JSON and looks like a GraphQL response (GraphQL over HTTP spec), reusing the existing GraphQLError model (message, locations, path, extensions) Failures while reading or parsing the body never replace the HTTP error, so retries and exception types are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative to #15, with a design based on the existing GraphQL types and the GraphQL over HTTP spec.
What
When a request fails with a non-success HTTP status,
GraphQLHttpExceptionnow exposes:ResponseBody(string): the raw response body, ornullif it was empty or could not be read.Response(GraphQLResponse): set when the body is a GraphQL response, otherwisenull. It is parsed only when the content type isapplication/jsonorapplication/graphql-response+jsonand the body haserrorsordata. It reuses the existingGraphQLErrormodel, soextensions(e.g.code),pathandlocationsare kept.The exception message adds the GraphQL errors when they were parsed. Otherwise it adds the raw body, truncated to 1000 characters.
Design notes
GraphQLHttpExceptionandRetryInterceptorbehaves as before.ResponseBody.errorsmust be an array of error objects. Any other shape, such as a stringerrors, leavesResponsenull and is only available throughResponseBodyand the message.Tests
GraphQLHttpExceptionTestscovers:extensionserrors🤖 Generated with Claude Code